package com.rattsoftware.server.serviceImpl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rattsoftware.server.admin.model.Department;
import com.rattsoftware.server.admin.model.exceptions.RattsSecurityException;
import com.rattsoftware.server.admin.model.paging.PagingLoadConfig;
import com.rattsoftware.server.admin.model.paging.PagingLoadResult;
import com.rattsoftware.server.dao.DepartmentDAO;
import com.rattsoftware.server.service.DepartmentService;

@Service("departmentService")
@Transactional
public class DepartmentServiceImpl implements DepartmentService{

	@Autowired
	private DepartmentDAO departmentDAO;
	private Logger log = LoggerFactory.getLogger(DepartmentServiceImpl.class);
	
	@Override
	public void deleteDepartment(Department department)
			throws RattsSecurityException {
		log.debug("Deleting department " + department.getName());
		departmentDAO.deleteDepartment(department);
	}

	@Override
	public void deleteDepartment(List<Integer> departmentIds)
			throws RattsSecurityException {
		for (Integer departmentId : departmentIds) {
			departmentDAO.deleteDepartment(getDepartment(departmentId));
		}
	}

	@Override
	public Integer getCourseCount(int departmentId)
			throws RattsSecurityException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Department getDepartment(int departmentId)
			throws RattsSecurityException {
		return departmentDAO.getDepartment(departmentId);
	}

	@Override
	public Department getDepartment(String departmentName)
			throws RattsSecurityException {
		return departmentDAO.getDepartment(departmentName);
	}

	@Override
	public PagingLoadResult<Department> getDepartmentList(
			PagingLoadConfig pagingLoadConfig) throws RattsSecurityException {
		return departmentDAO.getDepartmentList(pagingLoadConfig);
	}

	@Override
	public Department saveDepartment(Department department)
			throws RattsSecurityException {
		departmentDAO.saveDepartment(department);
		return department;
	}

	@Override
	public void saveDepartments(List<Department> departments)
			throws RattsSecurityException {
		for (Department department : departments) {
			saveDepartment(department);
		}
	}
}
